package com.ybkj.o2o.mc.controller.web;

import com.ybkj.o2o.mc.common.DataGrid;
import com.ybkj.o2o.mc.common.query.EnterpriseQuery;
import com.ybkj.o2o.mc.entity.Enterprise;
import com.ybkj.o2o.mc.entity.Passenger;
import com.ybkj.o2o.mc.manager.EnterpriseManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by shine on 15/8/19.
 */
@RestController
@RequestMapping("enterprise")
public class EnterpriseController {

  @Autowired
  private EnterpriseManager enterpriseManager;

  /**
   * 分页查询所有企业信息.
   *
   * @param page 页码
   * @param rows 每页显示数量
   */
  @RequestMapping(value = {"datagrid"}, method = RequestMethod.GET)
  @ResponseBody
  public DataGrid<Enterprise> list(@RequestParam("page") int page,
                                   @RequestParam("rows") int rows) {

    EnterpriseQuery enterpriseQuery = new EnterpriseQuery();
    enterpriseQuery.setPage(page);
    enterpriseQuery.setRows(rows);

    return enterpriseManager.findByEnterpriseQuery(enterpriseQuery);
  }


  @RequestMapping(value = "{id}/passenger", method = RequestMethod.GET)
  @ResponseBody
  public DataGrid<Passenger> findEnterprisePassenger(@PathVariable("id") Long id,
                                                     @RequestParam("page") int page,
                                                     @RequestParam("rows") int rows) {

    return enterpriseManager.findEnterprisePassenger(id, page, rows);
  }

  @RequestMapping(value = "{id}", method = RequestMethod.GET)
  @ResponseBody
  public Enterprise find(@PathVariable("id") Long id) {

    return enterpriseManager.fetch(id);
  }

}
